#ifndef BRICK_H
#define BRICK_H
#include <QLabel>
#include "ball.h"
class brick : public QObject{
    Q_OBJECT
public:
    brick(double, double, double, double, int style, QLabel *, ball *bba);
    //~brick(){};
    ball *bball;
    QLabel *bbrick;
    double brickX;
    double brickY;
    double Width;
    double Height;
    int style;
    void setWidth(double);
    void setHeight(double);
    void setX(double);
    void setY(double);
    void setStyle(int);
    double getX();
    double getY();
    double getWidth();
    double getHeight();
signals:
    void remove();
private slots:
    void PengZhuang(){
        double ballLeft = bball->getX()-bball->getR();
        double ballRight = bball->getX()+bball->getR();
        double ballBottom = bball->getY()+bball->getR();
        double ballTop = bball->getY()-bball->getR();
        double brickLeft = bbrick->geometry().x();
        double brickRight = bbrick->geometry().x()+bbrick->geometry().width();
        double brickTop = bbrick->geometry().y();
        double brickBottom = bbrick->geometry().y()+bbrick->geometry().height();

        if(this->bbrick->isVisible())
        {
           if(this->bball->speedy>0&&ballRight>=brickLeft&&ballLeft<=brickRight&&ballBottom>=brickTop-0.9&&ballBottom<=brickTop+2.1)
        {
         bball->speedy=-bball->speedy;
         this->bbrick->setVisible(false);
         emit remove();
         qDebug()<<"sahng";

        }
            else if(this->bball->speedy<0&&ballRight>=brickLeft&&ballLeft<=brickRight&&brickBottom+0.9>=ballTop&&brickBottom-2.1<=ballTop)
        {
         bball->speedy=-bball->speedy;
         this->bbrick->setVisible(false);
         emit remove();
         qDebug()<<"xia";

        }
            else if(this->bball->speedx>0&&ballBottom>=brickTop-1&&ballTop<=brickBottom-1&&ballRight>=brickLeft&&ballRight<=brickLeft+3.1)
        {
         bball->speedx=-bball->speedx;
         this->bbrick->setVisible(false);
         emit remove();
         qDebug()<<"Right";

        }
            else if(this->bball->speedx<0&&ballBottom>=brickTop-1&&ballTop<=brickBottom-1&&ballLeft<=brickRight&&ballLeft>=brickRight-3.1)
        {
         bball->speedx=-bball->speedx;
         this->bbrick->setVisible(false);
         emit remove();
         qDebug()<<"left";
        }
        }
    }


};

#endif // BRICK_H

